package com.wf.classRoomTest.Pro;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesLoader {
    // 静态变量用于存储配置数据
    private static int corePoolSize;
    private static int maxPoolSize;

    // 静态方法用于初始化配置数据
    public static void loadProperties() {
        Properties properties = new Properties();
        FileInputStream fis = null;

        try {
            fis = new FileInputStream("E:\\Java\\JavaSE\\code\\src\\com\\wf\\classRoomTest\\Pro\\threadPool.properties");
            properties.load(fis);

            // 读取配置项并存储到静态变量中
            corePoolSize = Integer.parseInt(properties.getProperty("corePoolSize"));
            maxPoolSize = Integer.parseInt(properties.getProperty("maxPoolSize"));

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    // 静态方法示例，使用从配置文件加载的数据
    public static void printPoolSizes() {
        System.out.println("Core Pool Size: " + corePoolSize);
        System.out.println("Max Pool Size: " + maxPoolSize);
    }

    public static void main(String[] args) {
        // 加载配置文件
        loadProperties();

        // 调用静态方法使用配置数据
        printPoolSizes();
    }
}
